package com.company.utils;


import java.io.*;

public class MyFileUtil {
    //复制文件
    public void copy(File source, File dest) {
        InputStream is = null;
        OutputStream os = null;
        try {
            is = new FileInputStream(source);
            os = new FileOutputStream(dest);
            byte[] bytes = new byte[1024];
            int read;
            while ((read = is.read(bytes)) != -1) {
                os.write(bytes, 0, read);
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                os.flush();
                os.close();
                is.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    //创建目录
    public int createFile(String filePath) {
        File file = new File(filePath);
        if (file.mkdir()) {
            return 1; //成功返回1
        } else {
            return -1;//不成功返回-1
        }
    }

}
